package com.sikao.app.adapter;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.TextView;

import com.sikao.app.R;
import com.sikao.app.bean.MyMailBean;
import com.sikao.app.myinterface.Callback;
import com.sikao.app.utils.TimeUtil;

import java.util.List;

/**
 * Created by y50 on 2016/5/6.
 */
public class MyMailAdapter extends BaseAdapter {

	private Context context;
	private Callback callback;
	private List<MyMailBean.ResBean.ListBean> beans;

	public MyMailAdapter(Context context, List<MyMailBean.ResBean.ListBean> beans, Callback callback) {
		this.context = context;
		this.beans = beans;
		this.callback = callback;
	}

	@Override
	public int getCount() {
		return beans.size();
	}

	@Override
	public Object getItem(int position) {
		return null;
	}

	@Override
	public long getItemId(int position) {
		return 0;
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		View view;
		ViewHolder holder;
		if (convertView == null) {
			view = View.inflate(context, R.layout.mail_list_item, null);
			holder = new ViewHolder(view);
			view.setTag(holder);
		} else {
			view = convertView;
			holder = (ViewHolder) view.getTag();
		}
		holder.tvMailTitle.setText(beans.get(position).getTitle());
		holder.tvMailContent.setText(beans.get(position).getContent());
		holder.tvMailTime.setText(TimeUtil.timeStampToTime(beans.get(position).getCreate_time(),TimeUtil.fotmatString2));
		holder.btnDelete.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				callback.notice(position);
			}
		});
		return view;
	}


	public class ViewHolder {
		public final TextView tvMailTitle;
		public final TextView tvMailTime;
		public final TextView tvMailContent;
		public final Button btnDelete;
		public final View root;

		public ViewHolder(View root) {
			tvMailTitle = (TextView) root.findViewById(R.id.tv_mail_title);
			tvMailTime = (TextView) root.findViewById(R.id.tv_mail_time);
			tvMailContent = (TextView) root.findViewById(R.id.tv_mail_content);
			btnDelete = (Button) root.findViewById(R.id.btn_delete);
			this.root = root;
		}
	}
}
